//统一管理咱们项目用户相关的接口
import request from "@/utils/request";
import type {
    LoginForm,
    UserAddOrUpdateForm,
    UserInfoReponseData,
    UserListReponseData,
    UserRoleForm,
    UserRouterReponseData,
} from "./type";
import {HandleResponseData, UuidForm} from "@/api/common/type";

//项目用户相关的请求地址
enum API {
    //登录
    loginUrl = "/bg/user/login",
    //获取当前用户
    userInfoUrl = "/bg/user/currentAccount",
    //退出
    logoutUrl = "/bg/user/logout",
    //路由以及按钮权限
    menuUrl = "/bg/menu/routerAndButtonList",
    //用户列表
    userPageListUrl = "/bg/user/pageList",
    //冻结
    userCloseUrl = "/bg/user/close",
    //用户分配角色
    userRoleUrl = "/bg/user/role",
    //添加用户
    userAddUrl = "/bg/user/add",
    //编辑用户
    userUpdateUrl = "/bg/user/update",
}

//登录接口
export const reqLogin = (data: LoginForm) => request.post<any, HandleResponseData>(API.loginUrl, data);
//获取用户信息
export const reqUserInfo = () => request.get<any, UserInfoReponseData>(API.userInfoUrl);
//退出登录
export const reqLogout = () => request.get<any, any>(API.logoutUrl)

export const reqCloseUser = (uuidForm: UuidForm) => request.post<any, any>(API.userCloseUrl,uuidForm)

export const reqRoleUser = (data : UserRoleForm) => request.post<any, any>(API.userRoleUrl,data)

export const reqAddOrUpdateUser = (data : UserAddOrUpdateForm) => {
    if (data.uuid){
        return request.post<any, HandleResponseData>(API.userUpdateUrl,data)
    }else {
        return request.post<any, HandleResponseData>(API.userAddUrl,data)
    }
}

export const reqUserList = (page: number, pageSize: number,usernameLike: string, type: number) =>
    request.get<any, UserListReponseData>(API.userPageListUrl+`?usernameLike=${usernameLike}&page=${page}&pageSize=${pageSize}&type=${type}`)

export const reqMenu = () => request.get<any, UserRouterReponseData>(API.menuUrl)

